package com.future;

/**
 * Description:
 *
 * @author weiruibai.vendor
 * Date: 2021/9/15 14:08
 */
public class CommonUtil {

    public static void main(String[] args) {

        ListNode listNode = generateRandomListNode(10, 10);
        while (listNode != null) {
            System.out.println(listNode.val);
            listNode = listNode.next;
        }
    }

    /**
     *
     * @param maxLength
     * @param maxValue
     * @return
     */
    public static int[] generateRandomList(int maxLength, int maxValue) {
        int length = (int) (maxLength * Math.random());
        int[] arr = new int[length];
        for (int i = 0; i < length; i++) {
            arr[i] = (int) ((Math.random()) * maxValue);
        }
        return arr;
    }

    /**
     * @param maxLength
     * @param maxValue
     * @return
     */
    public static ListNode generateRandomListNode(int maxLength, int maxValue) {
        int length = (int) (maxLength * Math.random());
        if (length == 0) {
            return null;
        }
        ListNode head = new ListNode((int) (maxValue * Math.random()));
        ListNode pre = head;
        while (length-- > 1) {
            ListNode curr = new ListNode((int) (maxValue * Math.random()));
            pre.next = curr;
            pre = curr;
        }
        return head;
    }
}
